package com.caregiver.watch.business.user.model.vo;

import com.caregiver.watch.business.user.enums.CareRelationshipEnum;
import com.caregiver.watch.business.user.enums.DeviceOnlineStatusEnum;
import com.caregiver.watch.business.user.model.po.UserCareRecipient;
import com.caregiver.watch.business.user.model.po.UserDevice;
import com.caregiver.watch.common.constant.NumberConstants;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @Description: 用户设备
 * @Author 疆戟
 * @Date 2025/8/24 21:15
 * @Version 1.0
 */
@Data
@Schema(description = "用户设备")
public class UserDeviceVo {

    @Schema(description = "设备ID")
    private Long deviceId;

    @Schema(description = "设备UUID")
    private String deviceUuid;
    /**
     * 设备名称
     */
    @Schema(description = "设备名称")
    private String deviceName;
    /**
     * 设备型号
     */
    @Schema(description = "设备型号")
    private String deviceModel;
    /**
     * 被照护人ID
     */
    @Schema(description = "被照护人ID")
    private Long recipientId;

    /**
     * 被照护人姓名
     */
    @Schema(description = "被照护人姓名")
    private String recipientName;

    /**
     * 被照护人头像
     */
    @Schema(description = "被照护人头像")
    private String recipientAvatar;

    /**
     * 与用户关系（本人、父亲、母亲、配偶等）
     */
    @Schema(description = "与用户关系（本人、父亲、母亲、配偶等）")
    private CareRelationshipEnum relationship;

    /**
     * 电量
     */
    @Schema(description = "电量")
    private Integer battery;


    @Schema(description = "跟新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    /**
     * 在线状态
     */
    @Schema(description = "在线状态(在线,离线)")
    private DeviceOnlineStatusEnum status;

    /**
     * 是否绑定陪护人
     */
    @Schema(description = "是否绑定陪护人")
    private Boolean isBindCareRecipient;


    public static UserDeviceVo build(UserDevice userDevice, UserCareRecipient userCareRecipient, String recipientAvatar) {
        UserDeviceVo userDeviceVo = new UserDeviceVo();
        userDeviceVo.deviceId = userDevice.getDeviceId();
        userDeviceVo.deviceUuid = userDevice.getDeviceUuid();
        userDeviceVo.deviceName = userDevice.getDeviceName();
        userDeviceVo.deviceModel = userDevice.getDeviceModel();
        userDeviceVo.recipientAvatar = recipientAvatar;
        userDeviceVo.recipientId = userDevice.getRecipientId();
        userDeviceVo.battery = userDevice.getBatteryLevel();
        userDeviceVo.updateTime = userDevice.getUpdateTime();
        userDeviceVo.status = DeviceOnlineStatusEnum.parse(userDevice.getOnlineStatus());
        if (Objects.nonNull(userCareRecipient)) {
            userDeviceVo.recipientName = userCareRecipient.getName();
            userDeviceVo.relationship = CareRelationshipEnum.parse(userCareRecipient.getRelationship());
            userDeviceVo.isBindCareRecipient = Boolean.TRUE;
        } else {
            userDeviceVo.isBindCareRecipient = Boolean.FALSE;
        }
        return userDeviceVo;
    }
}
